package com.ojoin.trade.supplyloan_core.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ojoin.trade.common.utils.CommonUtils;
import com.ojoin.trade.common.web.controller.SimpleBaseController;
import com.ojoin.trade.common.web.domain.Result;
import com.ojoin.trade.common_core.web.domain.TbMerchantInfo;
import com.ojoin.trade.common_core.web.service.TbMerchantInfoBaseService;

@Controller
@RequestMapping("/operate/merchantinfo")
  
public class SlMerchantInfoController  extends SimpleBaseController {
	 
	private Logger log = LoggerFactory.getLogger(SlMerchantInfoController.class);
 
	@Autowired
	private TbMerchantInfoBaseService infoService;

	@ResponseBody
	@RequestMapping(value = "/querylistnamemap", method = {RequestMethod.POST,RequestMethod.GET})
	public Result queryListNameMap(String name) {
       
		try { 
			List<Map<String,String>> li = new ArrayList<Map<String,String>>();
			  
		
			List<TbMerchantInfo> list =infoService.queryByNameVague(name);
			if(null != list){
				for(int i=0;i<list.size();i++){
					TbMerchantInfo info = list.get(i);
					if(!CommonUtils.isEmpty(info.getMchName())){
						if(CommonUtils.isEmpty(name) || info.getMchName().contains(name)){
							Map<String,String> map = new HashMap<String,String>();
							map.put("value", info.getIdOfTbMerchantUser()+"");
                            map.put("mhtNo",info.getMhtNo());
							map.put("label", info.getMchName()+"("+info.getName()+")"); 
							li.add(map);
						}
						
					} 
				}
			}   
			return new Result(Result.Status.OK, li);
		} catch (Exception e) {
			log.error("", e); 
			return new Result(Result.Status.ERROR, "查询商户出错");
		}

	}
	
	
   
	

	
	
	

}